package homework.module3;

import java.util.HashMap;
import java.util.Map;

public class printHashMap {

    public static void main(String[] args){

        String countStr = "123,456,789,123,456";
        String[] strArray = countStr.split(",");

        Map<String, Integer> countMap = new HashMap<>();

        for (int i=0;i<strArray.length;i++){
            String childStr = strArray[i];

            // 如果已经存在该字符串，数量+1，不存在的话数量为1
            if (countMap.keySet().contains(childStr)){
                int count = countMap.get(childStr) + 1;
                countMap.put(childStr, count);
            }else{
                countMap.put(childStr, 1);
            }
        }

        for (String keyStr: countMap.keySet()){
            System.out.println(keyStr + "的数量是：" + countMap.get(keyStr));
        }

    }

}
